package com.example.demo.thread.singleton;

/**
 * @Description: 双重检查锁实现单例模式 不加volatile因为指令重排序，导致获取到状态不正确的实例
 * @Author: LLL
 * @Date: 2020-03-19 15:33
 **/
public class DCLSingleton {

    private DCLSingleton() {
    }

    private static volatile DCLSingleton instance = null;

    public static DCLSingleton getInstance() {
        if (instance == null) {
            synchronized (DCLSingleton.class) {
                if (instance == null) {
                    instance = new DCLSingleton();
                }
            }
        }
        return instance;
    }
}
